***********HCUP, TX, and CA 2009 INPATIENT DISCHARGE DATA;
***********SID FILES CONSTRUCTED ON NBER SERVER**********;
***********COPY SAS FILES TO HOME DIRECTORY**************;

libname hcup1999 ".";
libname hcup2009 ".";
libname hcup ".";
libname sedd ".";

data hcup.all2009;
set texas2009 California2009 totalall;
run;


proc sql;
create table hcup.totalall as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.all2009
where byear GT 1800
group by bmonth, byear;
quit;


data hcup.totalall;
set hcup.totalall;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

**Input file for regressions;

PROC EXPORT DATA= hcup.TOTALALL 
            OUTFILE= "allraces2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.black2009;
set texas2009black californiablack2009 totalblack;
run;


proc sql;
create table hcup.totalblack2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,
sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.black2009
where byear GT 1800
group by bmonth, byear;
quit;

*Input file for simulations;

PROC EXPORT DATA= hcup.totalblack2009 
            OUTFILE= "totalblack2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


data hcup.totalblack2009;
set hcup.totalblack2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

**Input file for regressions;

PROC EXPORT DATA= hcup.totalblack2009 
            OUTFILE= "black2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.nonblack2009;
set texas2009nonblack Californianotblack2009 totalnotblack;
run;


proc sql;
create table hcup.totalnonblack2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.nonblack2009
where byear GT 1800
group by bmonth, byear;
quit;

data hcup.totalnonblack2009;
set hcup.totalnonblack2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

**Input file for regressions;

PROC EXPORT DATA= hcup.totalnonblack2009 
            OUTFILE= "nonblack2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

***********************2009 ANALYSIS on 1999 STATES;


data hcup.all99states;
set texas2009 California2009 total99states;
run;


proc sql;
create table hcup.TOTAL99states as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.all99states
where byear GT 1800
group by bmonth, byear;
quit;

data hcup.TOTAL99states;
set hcup.TOTAL99states;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;


PROC EXPORT DATA= hcup.TOTAL99states 
            OUTFILE= "allraces99states.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


data hcup.black99states;
set texas2009black Californiablack2009 totalblack99states;
run;


proc sql;
create table hcup.totalblack99states as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.black99states
where byear GT 1800
group by bmonth, byear;
quit;


data hcup.totalblack99states;
set hcup.totalblack99states;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;


PROC EXPORT DATA= hcup.totalblack99states
            OUTFILE= "black99states.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


data hcup.totalnonblack99states;
set texas2009nonblack Californianotblack2009 hcup2009.totalnotblack99states;
run;


proc sql;
create table hcup.totalnonblack99states as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.totalnonblack99states
where byear GT 1800
group by bmonth, byear;
quit;

data hcup.totalnonblack99states;
set hcup.totalnonblack99states;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.totalnonblack99states
            OUTFILE= "nonblack99states.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


**********LOW INCOME PATIENT SAMPLE*******;

data hcup.lowincomeall2009;
set texas2009li Californiali2009 totalallli;
run;


proc sql;
create table hcup.lowincome2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.lowincomeall2009
where byear GT 1800
group by bmonth, byear;
quit;

**Input for regressions;

data hcup.lowincome2009;
set hcup.lowincome2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.lowincome2009 
            OUTFILE= "allracesli2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.lowincomeblack2009;
set texas2009blackli Californialiblack2009 totalblackli;
run;

proc sql;
create table hcup.lowincomeblack2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.lowincomeblack2009
where byear GT 1800
group by bmonth, byear;
quit;

**Input for simulations;

PROC EXPORT DATA= hcup.lowincomeblack2009 
            OUTFILE= "lowincomeblack2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


data hcup.lowincomeblack2009;
set hcup.lowincomeblack2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

**Input for regressions;

PROC EXPORT DATA= hcup.lowincomeblack2009 
            OUTFILE= "blackli2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.lowincomenotblack2009;
set kentucky.ky2009nonblackli texas2009nonblackli Californialinotblack2009 hcup2009.totalnotblackli;
run;


proc sql;
create table hcup.lowincomenotblack2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.lowincomenotblack2009
where byear GT 1800
group by bmonth, byear;
quit;

**Input for regressions;

data hcup.lowincomenotblack2009;
set hcup.lowincomenotblack2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.lowincomenotblack2009 
            OUTFILE= "nonblackli2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


***********2009 EMERGENCY DEPARTMENT ANALYSIS************;

data hcup.sedd2009;
set calied2009 sedd.totalall;
run;


proc sql;
create table hcup.sedd2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear

from hcup.sedd2009
where byear GT 1800
group by bmonth, byear;
quit;

***Input file for regressions;

data hcup.sedd2009;
set hcup.sedd2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.sedd2009 
            OUTFILE= "Ed.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.blacksedd2009;
set calied.blackcalied2009 sedd.totalblack;
run;


proc sql;
create table hcup.blacksedd2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.blacksedd2009
where byear GT 1800
group by bmonth, byear;
quit;


***Input file for simulations;

PROC EXPORT DATA= hcup.blacksedd2009 
            OUTFILE= "edblack2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

***Input file for regressions;

data hcup.blacksedd2009;
set hcup.blacksedd2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.blacksedd2009 
            OUTFILE= "Edblack.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.nonblacksedd2009;
set notblackcalied2009 sedd.totalnotblack;
run;

proc sql;
create table hcup.nonblacksedd2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.nonblacksedd2009
where byear GT 1800
group by bmonth, byear;
quit;



***Input file for regressions;

data hcup.nonblacksedd2009;
set hcup.nonblacksedd2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.nonblacksedd2009 
            OUTFILE= "nonblacked.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


***********2009 EMERGENCY DEPARTMENT ANALYSIS LOW INCOME**;
***********SEDD FILES CONSTRUCTED ON NBER SERVER**********;
***********COPY SAS FILES TO HOME DIRECTORY**************;
***********SEE /disk/data3/sedd.work/millers/2009*********;

data hcup.EDlowincomeall2009;
set licalied2009 sedd.totalallli;
run;

proc sql;
create table hcup.EDlowincomeall2009 as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear

from hcup.EDlowincomeall2009
where byear GT 1800
group by bmonth, byear;
quit;

data hcup.EDlowincomeall2009;
set hcup.EDlowincomeall2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

***Input file for regressions;

PROC EXPORT DATA= hcup.EDlowincomeall2009 
            OUTFILE= "allracesedli.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.EDlowincomeallblack;
set blacklicalied2009 sedd.totalblackli;
run;


proc sql;
create table hcup.EDlowincomeallblack as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.EDlowincomeallblack
where byear GT 1800
group by bmonth, byear;
quit;

***Input file for simulations;

PROC EXPORT DATA= hcup.EDlowincomeallblack 
            OUTFILE= "lowincedblack.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


***Input file for regressions;

data hcup.EDlowincomeallblack;
set hcup.EDlowincomeallblack;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.EDlowincomeallblack 
            OUTFILE= "blackedli.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data hcup.EDlowincomenotblack;
set calied.notblacklicalied2009 sedd.nonblackli;
run;


proc sql;
create table hcup.EDlowincomenotblack as select 
sum(HCUPChronic) as HCUPChronic,
sum(cost) as cost,
sum(charges) as charges,

sum(publicc) as publicc,
sum(privatec) as privatec,
sum(selfc) as selfc,
sum(freecarec) as freecarec,


sum(infect) as infect,
sum(neoplasms) as neoplasms,
sum(endometa) as endometa,
sum(blood) as blood,
sum(mentaldisorders) as mentaldisorders,
sum(nervoussys) as nervoussys,
sum(sense) as sense,
sum(circulatory) as circulatory,
sum(respiratory) as respiratory,
sum(digestive) as digestive,
sum(genitourinary) as genitourinary,
sum(skin) as skin,
sum(muscle) as muscle,
sum(congenital) as congenital,
sum(perinatal) as perinatal,
sum(illdefined) as illdefined,
sum(injpois) as injpois,

sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear

from hcup.EDlowincomenotblack
where byear GT 1800
group by bmonth, byear;
quit;

***Input file for regressions;

data hcup.EDlowincomenotblack;
set hcup.EDlowincomenotblack;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
lognp=log(count);
run;

PROC EXPORT DATA= hcup.EDlowincomenotblack 
            OUTFILE= "nonblackedli.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


************1999;

data hcup.all1999;
set  California1999 hcup1999.totalall texas1999;
run;


proc sql;
create table hcup.totalall1999 as select 
sum(HCUPChronic) as HCUPChronic,
sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.all1999
where byear GT 1800
group by bmonth, byear;
quit;



PROC EXPORT DATA= hcup.totalall1999 
            OUTFILE= "totalall1999.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


data hcup.black1999;
set  CaliforniaBlack1999 hcup1999.totalblack texas1999black;
run;


proc sql;
create table hcup.totalblack1999 as select 
sum(HCUPChronic) as HCUPChronic,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.black1999
where byear GT 1800
group by bmonth, byear;
quit;

PROC EXPORT DATA= hcup.totalblack1999 
            OUTFILE= "totalblack1999.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


data hcup.nonblack1999;
set CaliforniaNotBlack1999 hcup1999.totalnotblack texas1999nonblack;
run;


proc sql;
create table hcup.Nonblack1999 as select 
sum(HCUPChronic) as HCUPChronic,
sum(Appendicitis) as Appendicitis,
sum(injury) as injury,
sum(fracture) as fracture,
sum(count) as count,
sum(preg) as preg,
bmonth as bmonth,
byear as byear
from hcup.Nonblack1999
where byear GT 1800
group by bmonth, byear;
quit;

PROC EXPORT DATA= hcup.Nonblack1999 
            OUTFILE= "Nonblack1999.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;



***********2009 FILES STATE-BY-STATE ANALYSIS************;
*****POPULATION FILE: From SEER/Census*******************;

data popbyage (keep=Year FIPS Population);
 infile 'us.state.1981_2013.singleages.race.adjusted.txt';
  input @1 Year 4. @5 State $2. @7 FIPS 2. @9 County 3. @12 Registry 2. @14 Race 1. @15 Origin 1. @16 Sex 1. @17 Age 2. @19 Population 8.;
if year=2009;
if age GE 22 and age LE 30;
run;

  proc sql;
  create table popall as select sum(Population) as Population, FIPS as fips from popbyage
  group by fips
  order by fips;
  quit;

data hcup.erbystate2009;
set sedd.allerbystate calied2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
run;

proc sort data=hcup.erbystate2009;
by fips;
quit;

data hcup.erbystate2009;
merge hcup.erbystate2009 popall;
by fips;
if bmonth=. then delete;
run;


PROC EXPORT DATA= hcup.erbystate2009
            OUTFILE= "erbystate.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;



data popbyage (keep=Year FIPS Population);
 infile 'us.state.1981_2013.singleages.race.adjusted.txt';
  input @1 Year 4. @5 State $2. @7 FIPS 2. @9 County 3. @12 Registry 2. @14 Race 1. @15 Origin 1. @16 Sex 1. @17 Age 2. @19 Population 8.;
if year=2009;
if age GE 22 and age LE 30;
if race=2;
run;

  proc sql;
  create table popall as select sum(Population) as Population, FIPS as fips from popbyage
  group by fips
  order by fips;
  quit;

data hcup.blackerbystate2009;
set sedd.blackerbystate calied.blackcalied2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
run;


proc sort data=hcup.blackerbystate2009;
by fips;
quit;

data hcup.blackerbystate2009;
merge hcup.blackerbystate2009 popall;
by fips;
if bmonth=. then delete;
run;


PROC EXPORT DATA= hcup.blackerbystate2009
            OUTFILE= "blackerbystate.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;



data popbyage (keep=Year FIPS Population);
 infile 'us.state.1981_2013.singleages.race.adjusted.txt';
  input @1 Year 4. @5 State $2. @7 FIPS 2. @9 County 3. @12 Registry 2. @14 Race 1. @15 Origin 1. @16 Sex 1. @17 Age 2. @19 Population 8.;
if year=2009;
if age GE 22 and age LE 30;
if race NE 2;
run;

  proc sql;
  create table popall as select sum(Population) as Population, FIPS as fips from popbyage
  group by fips
  order by fips;
  quit;

data hcup.notblackerbystate2009;
set sedd.notblackerbystate calied.notblackcalied2009;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
run;

proc sort data=hcup.notblackerbystate2009;
by fips;
quit;

data hcup.notblackerbystate2009;
merge hcup.notblackerbystate2009 popall;
by fips;
if bmonth=. then delete;
run;


PROC EXPORT DATA= hcup.notblackerbystate2009
            OUTFILE= "notblackerbystate2009.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


****************1999 by state;
********************************;

data popbyage (keep=Year FIPS Population);
 infile 'us.state.1981_2013.singleages.race.adjusted.txt';
  input @1 Year 4. @5 State $2. @7 FIPS 2. @9 County 3. @12 Registry 2. @14 Race 1. @15 Origin 1. @16 Sex 1. @17 Age 2. @19 Population 8.;
if year=1999;
if age GE 12 and age LE 20;
run;

  proc sql;
  create table popall as select sum(Population) as Population, FIPS as fips from popbyage
  group by fips
  order by fips;
  quit;

data hcup.bystate1999;
set hcup1999.totalallbystate California1999 texas1999;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
run;


proc sort data=hcup.bystate1999;
by fips;
quit;

data hcup.bystate1999;
merge hcup.bystate1999 popall;
by  fips;
if bmonth=. then delete;
run; 

PROC EXPORT DATA= hcup.bystate1999
            OUTFILE= "bystate1999.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;

data popbyage (keep=Year FIPS Population);
 infile 'us.state.1981_2013.singleages.race.adjusted.txt';
  input @1 Year 4. @5 State $2. @7 FIPS 2. @9 County 3. @12 Registry 2. @14 Race 1. @15 Origin 1. @16 Sex 1. @17 Age 2. @19 Population 8.;
if year=1999;
if age GE 12 and age LE 20;
if race=2;
run;

  proc sql;
  create table popall as select sum(Population) as Population, FIPS as fips from popbyage
  group by fips
  order by fips;
  quit;


data hcup.blackbystate1999;
set Californiablack1999 hcup1999.totalblackbystate texas1999black;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
run;



proc sort data=hcup.blackbystate1999;
by fips;
quit;

data hcup.blackbystate1999;
merge hcup.blackbystate1999 popall;
by fips;
if bmonth=. then delete;
run;


PROC EXPORT DATA= hcup.blackbystate1999
            OUTFILE= "blackbystate1999.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;



data popbyage (keep=Year FIPS Population);
 infile 'us.state.1981_2013.singleages.race.adjusted.txt';
  input @1 Year 4. @5 State $2. @7 FIPS 2. @9 County 3. @12 Registry 2. @14 Race 1. @15 Origin 1. @16 Sex 1. @17 Age 2. @19 Population 8.;
if year=1999;
if age GE 12 and age LE 20;
if race NE 2;
run;

  proc sql;
  create table popall as select sum(Population) as Population, FIPS as fips from popbyage
  group by fips
  order by fips;
  quit;

data hcup.nonblackbystate1999;
set Californianotblack1999 hcup1999.totalnotblackbystate texas1999nonblack;
if byear le 1978 then delete;
if byear ge 1988 then delete;
if byear=1987 and bmonth gt 9 then delete;
if byear=1979 and bmonth lt 10 then delete;
run;


proc sort data=hcup.nonblackbystate1999;
by fips;
quit;

data hcup.nonblackbystate1999;
merge hcup.nonblackbystate1999 popall;
by fips;
if bmonth=. then delete;
run;


PROC EXPORT DATA= hcup.nonblackbystate1999
            OUTFILE= "nonblackbystate1999.csv" 
            DBMS=CSV REPLACE;
     PUTNAMES=YES;
RUN;


